<?php session_start(); ?>
<?php include "libfunc.php";?>
<?php if (!empty($_SESSION['admUser']) && !empty($_SESSION['admPass'])) { ?>
<html>
 <head>
  <title>.: Admin Room ClothingCorp :.</title>
  <link href="admInc/cssMainStyle.css" type="text/css" rel="stylesheet">
  <link href="admInc/cssTableStyle.css" type="text/css" rel="stylesheet">
  <link href="admInc/cssAdditionStyle.css" type="text/css" rel="stylesheet">
  <link href="admInc/cssTableNavigation.css" type="text/css" rel="stylesheet">
 </head>
 <body class="fix">
  <div id="wrapper">
   <div id="header">
    <div class="titleHeader"><center>
     <img src="image/logo2.png" border="0">
	</div><!-- titleHeader //-->
	<div class="subTitleHeader"><center>
	 - Website Administrator Control Panel -
	</div><!-- subTitleHeader //-->
   </div><!-- header //--></center>
   <div id="mainContent">
    <div id="leftColumn">
	 <div class="navigation">
	  <table border="0" width="100%" bgcolor="white">
	  <tr>
	    <td class="headerTable" align="center"><b>Admin Page</b></td>
	  </tr>
	  <tr>
	    <td><img src="image/tag_blue.png"><a href="adminLayout.php"> Halaman Utama</a></td>
	  </tr>
	  <tr>
	    <td><img src="image/tag_blue.png"><a href="newInformation.php"> Informasi Terkini</a></td>
	  </tr>
	  <tr>
	    <td><img src="image/tag_blue.png"><a href="LogOut.php" onClick="return confirm('Apakah Anda benar-benar akan keluar dari halaman Admin ?')"> Keluar</a></td>
	  </tr>
	  <tr>
	    <td></td>
	  </tr>
	  <tr>
	    <td></td>
	  </tr>
      <tr>
	    <td></td>
	  </tr>
      <tr>
	    <td></td>
	  </tr>
	  <tr>
	    <td class="headerTable" align="center"><b>Data Kategori</b></td>
	  </tr>
	  <tr>
	    <td><img src="image/tag_blue.png"><a href="tambah_kategori.php"> Tambah Kategori</a></td>
	  </tr>
	  <tr>
	    <td><img src="image/tag_blue.png"><a href="view_kategori.php"> View Kategori</a></td>
	  </tr>
	  <tr>
	    <td><img src="image/tag_blue.png"><a href="pencarian_kategori.php"> Pencarian Kategori</a></td>
	  </tr>
      <tr>
	    <td></td>
	  </tr>
      <tr>
	    <td></td>
	  </tr>
	  <tr>
	    <td class="headerTable" align="center"><b>Data Member</b></td>
	  </tr>
	  <tr>
	    <td><img src="image/tag_blue.png"><a href="tambah_member.php"> Tambah Member</a></td>
	  </tr>
	  <tr>
	    <td><img src="image/tag_blue.png"><a href="view_member.php"> View Member</a></td>
	  </tr>
	  <tr>
	    <td><img src="image/tag_blue.png"><a href="pencarian_member.php"> Pencarian Member</a></td>
	  </tr>
      <tr>
	    <td></td>
	  </tr>
      <tr>
	    <td></td>
	  </tr>
	  <tr>
	    <td class="headerTable" align="center"><b>Data Produk</b></td>
	  </tr>
	  <tr>
	    <td><img src="image/tag_blue.png"><a href="view_produk.php"> View Produk</a></td>
	  </tr>
	  <tr>
	    <td><img src="image/tag_blue.png"><a href="pencarian_produk.php"> Pencarian Produk</a></td>
	  </tr>
	  <tr>
		<td></td>
	  </tr>
	  <tr>
		<td></td>
	  </tr>
	  <tr>
	    <td class="headerTable" align="center"><b>Data Penjual</b></td>
	  </tr>
	  <tr>
	    <td><img src="image/tag_blue.png"><a href="tambah_pejual.php"> Tambah Penjual</a></td>
	  </tr>
	  <tr>
	    <td><img src="image/tag_blue.png"><a href="view_penjual.php"> View Penjual</a></td>
	  </tr>
	  <tr>
	    <td><img src="image/tag_blue.png"><a href="pencarian_penjual.php"> Pencarian Penjual</a></td>
	  </tr>
      <tr>
	    <td></td>
	  </tr>
	  <tr>
		<td></td>
	  </tr>
	  <tr>
	    <td class="headerTable" align="center"><b>Data Pesanan</b></td>
	  </tr>
	  <tr>
	    <td><img src="image/tag_blue.png"><a href="view_pesanan.php"> View Pesanan</a></td>
	  </tr>
	  <tr>
	    <td><img src="image/tag_blue.png"><a href="pencarian_pesanan.php"> Pencarian Pesanan</a></td>
	  </tr>
      <tr>
	    <td></td>
	  </tr>
      <tr>
	    <td></td>
	  </tr>
	  
	</table>
	 </div><!-- navigation //-->
	</div><!-- leftColumn //-->
	<div id="rightColumn">
	 <div class="content">
       	<?php 
		//----------- ambil value dari field cari dan keywordnya
		$fieldcari = $_POST['fieldcari'];
		$keyword   = $_POST['keyword'];
		
		$link = koneksi_db();
		
		//------- jika keyword id_buku
		if ($fieldcari == "judul"){
			
			$sql  = "select * from dtbuku where judul like '$keyword'";
			
			
			$res  = mysql_query($sql,$link);
			$banyakrecord = mysql_num_rows($res);
			$q = mysql_fetch_array($res);
			
			
			if ($banyakrecord >= 1) {
				
				$sql2 = "select * from pesanan,pesanan_item where pesanan.id_pesanan = pesanan_item.id_pesanan and pesanan_item.id_buku = '$q[id_Buku]'";
				
				$res2 = mysql_query($sql2,$link);
				?>
				<fieldset>
					<legend>View Data Pesanan</legend>
						<table align='center' class="tableView">
							<tr class="trTable">
								<td>NO</td>
								<td>ID Pesanan</td>
								<td>Nama Member</td>
								<td>Waktu Pesanan</td>
								<td>Dichekout</td>
								<td>Diarsipkan</td>
								<td>Aksi</td>
							</tr>
						<?php
						$no = $posisi+1;
						while( $data = mysql_fetch_array($res2) ){
							?>
							<tr>
								<td><?php echo $no; ?></td>
								<td><?php echo $data['Id_pesanan']; ?></td>
								<td>
							<?php
								$sql_p =  "select dtmember.nama from dtmember,dtpesanan
											where dtmember.id_member = dtpesanan.id_member
											and	
											dtmember.id_member = '$data[id_member]'
											";
								$query_p = mysql_query($sql_p,$link);
								$hasil_p = mysql_fetch_array($query_p);
						 
								echo $hasil_p['nama'];
							?>	
								</td>
								<td>
								<?php 
									echo $data['waktu'];
								?>
								</td>
								<td>
							<?php 
								if ($data['dichekout']=='T') {
									echo "Belum";
								}else{
									echo "Sudah";
								}
							?>
								</td>
								<td>
							<?php 
								if ($data['diarsipkan']=='T') {
									echo "Belum";
								}else{
									echo "Sudah";
								}
							?>
								</td>
								<td align="center">
									<a href="detail_pesanan.php?id=<?php echo $data['Id_pesanan']; ?>&idm=<?php echo $data['id_member']; ?>"><img src="image/magnifier.png" border="0" title="Lihat !"></a>
								</td>
							</tr>
							<?php
							$no++;
				}?>
						</table><br><br>
				</fieldset>
			<?php
			}else{?>
				<div id="keterangan">
					<fieldset>
					<legend>Keterangan</legend>
					Tidak ada data <?php echo $keyword; ?> dari hasil pencarian !!!<br><br>
					<input type="button" onClick="javascript:history.back()" value="Cari Lagi !">
					</fieldset>
				</div>
			<?php
			}
				
		}else{
			
			$sql  = "select * from dtmember where nama='$keyword'";
			
			$res  = mysql_query($sql,$link);
			$banyakrecord = mysql_num_rows($res);
			$q = mysql_fetch_array($res);
			$b = $banyakrecord - 1;
			
			if ($banyakrecord >= 1) {
				$sql2 = "select * from dtpesanan where dtpesanan.id_member = '$q[id_member]'";
				
				$res2 = mysql_query($sql2,$link);
				
				?>
				<fieldset>
					<legend>View Data Pesanan</legend>
						<table align='center' class="tableView">
							<tr class="trTable">
								<td>NO</td>
								<td>ID Pesanan</td>
								<td>Nama Member</td>
								<td>Waktu Pesanan</td>
								<td>Dichekout</td>
								<td>Diarsipkan</td>
								<td>Aksi</td>
							</tr>
						<?php
						$no = $posisi+1;
						while( $data = mysql_fetch_array($res2) ){
							?>
							<tr>
								<td><?php echo $no; ?></td>
								<td><?php echo $data['Id_pesanan']; ?></td>
								<td>
							<?php
								$sql_p =  "select dtmember.nama from dtmember,dtpesanan
											where dtmember.id_member = dtpesanan.id_member
											and	
											dtmember.id_member = '$data[id_member]'
											";
								$query_p = mysql_query($sql_p,$link);
								$hasil_p = mysql_fetch_array($query_p);
						 
								echo $hasil_p['nama'];
							?>	
								</td>
								<td>
								<?php 
									echo $data['waktu'];
								?>
								</td>
								<td>
							<?php 
								if ($data['dichekout']=='T') {
									echo "Belum";
								}else{
									echo "Sudah";
								}
							?>
								</td>
								<td>
							<?php 
								if ($data['diarsipkan']=='T') {
									echo "Belum";
								}else{
									echo "Sudah";
								}
							?>
								</td>
								<td align="center">
									<a href="detail_pesanan.php?id=<?php echo $data['Id_pesanan']; ?>&idm=<?php echo $data['id_member']; ?>"><img src="image/magnifier.png" border="0" title="Lihat !"></a>
								</td>
							</tr>
							<?php
							$no++;
				}?>
						</table><br><br>
				</fieldset>
			<?php
			}else{?>
				<div id="keterangan">
					<fieldset>
					<legend>Keterangan</legend>
					Tidak ada data <?php echo $keyword; ?> dari hasil pencarian !!!<br><br>
					<input type="button" onClick="javascript:history.back()" value="Cari Lagi !">
					</fieldset>
				</div>
			<?php
			}
			
			
		}
		
		
		?>
     </div><!-- content //-->
	</div><!-- rightColumn //-->
   </div><!-- mainContent //-->
  </div><!-- wrapper //-->
 </body>
</html>
<?php
}else{
  echo "<script language='javascript'>alert('Silakan Sign In Terlebih Dahulu')</script>";
  echo "<script language='javascript'>window.location = '../admin/'</script>";
}